<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="######1). 文件格式">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Android-解析resources-arsc文件">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Android-Plugin/Android-解析resources-arsc文件/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="######1). 文件格式">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-935086864cb5429c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-06T11:11:17.913Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android-解析resources-arsc文件">
<meta name="twitter:description" content="######1). 文件格式">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/3110861-935086864cb5429c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Android-Plugin/Android-解析resources-arsc文件/"/>





  <title>Android-解析resources-arsc文件 | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Android-Plugin/Android-解析resources-arsc文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android-解析resources-arsc文件</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>######1). 文件格式<br><img src="https://upload-images.jianshu.io/upload_images/3110861-935086864cb5429c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="resources.arsc文件格式.png"></p>
<a id="more"></a>
<p>######2). 头部信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * Resource.arsc文件格式是由一系列的chunk构成，每一个chunk均包含ResChunk_header</span><br><span class="line"> * </span><br><span class="line"> * struct ResChunk_header</span><br><span class="line">&#123;</span><br><span class="line">    // Type identifier for this chunk.  The meaning of this value depends</span><br><span class="line">    // on the containing chunk.</span><br><span class="line">    uint16_t type;</span><br><span class="line"></span><br><span class="line">    // Size of the chunk header (in bytes).  Adding this value to</span><br><span class="line">    // the address of the chunk allows you to find its associated data</span><br><span class="line">    // (if any).</span><br><span class="line">    uint16_t headerSize;</span><br><span class="line"></span><br><span class="line">    // Total size of this chunk (in bytes).  This is the chunkSize plus</span><br><span class="line">    // the size of any data associated with the chunk.  Adding this value</span><br><span class="line">    // to the chunk allows you to completely skip its contents (including</span><br><span class="line">    // any child chunks).  If this value is the same as chunkSize, there is</span><br><span class="line">    // no data associated with the chunk.</span><br><span class="line">    uint32_t size;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResChunkHeader &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * 当前这个chunk的类型</span><br><span class="line">	 */</span><br><span class="line">	public short type;</span><br><span class="line">	/**</span><br><span class="line">	 * 当前chunk的头部大小</span><br><span class="line">	 */</span><br><span class="line">	public short headerSize;</span><br><span class="line">	/**</span><br><span class="line">	 * 当前chunk的大小</span><br><span class="line">	 */</span><br><span class="line">	public int size;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 获取Chunk Header所占字节数</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	public int getHeaderSize() &#123;</span><br><span class="line">		return 2 + 2 + 4;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;type: &quot; + Util.bytesToHexString(Util.int2Byte(type)) + &quot;,headerSize: &quot; + headerSize + &quot;,size: &quot; + size;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######3). 资源索引表的头部信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * Resources.arsc文件的第一个结构是资源索引表头部</span><br><span class="line"> * 描述Resources.arsc文件的大小和资源包数量</span><br><span class="line"> * </span><br><span class="line"> * struct ResTable_header</span><br><span class="line">&#123;</span><br><span class="line">    struct ResChunk_header header;</span><br><span class="line"></span><br><span class="line">    // The number of ResTable_package structures.</span><br><span class="line">    uint32_t packageCount;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResTableHeader &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * 标准的Chunk头部信息格式</span><br><span class="line">	 */</span><br><span class="line">	public ResChunkHeader header;</span><br><span class="line">	/**</span><br><span class="line">	 * 被编译的资源包个数</span><br><span class="line">	 * Android 中一个apk可能包含多个资源包，默认情况下都只有一个就是应用的包名所在的资源包</span><br><span class="line">	 */</span><br><span class="line">	public int packageCount;</span><br><span class="line">	</span><br><span class="line">	public ResTableHeader() &#123;</span><br><span class="line">		header = new ResChunkHeader();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 获取当前Table Header所占字节数</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	public int getHeaderSize() &#123;</span><br><span class="line">		return header.getHeaderSize() + 4;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;header:&quot; + header.toString() + &quot;\n&quot; + &quot;packageCount:&quot;+packageCount;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######4). 资源项的值字符串资源池<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 资源索引表头部的是资源项的值字符串资源池，这个字符串资源池包含了所有的在资源包里面所定义的资源项的值字符串</span><br><span class="line"> * 一个字符串可以对应多个ResStringPool_span和一个ResStringPool_ref</span><br><span class="line"> * struct ResStringPool_header</span><br><span class="line">&#123;</span><br><span class="line">    struct ResChunk_header header;</span><br><span class="line"></span><br><span class="line">    // Number of strings in this pool (number of uint32_t indices that follow</span><br><span class="line">    // in the data).</span><br><span class="line">    uint32_t stringCount;</span><br><span class="line"></span><br><span class="line">    // Number of style span arrays in the pool (number of uint32_t indices</span><br><span class="line">    // follow the string indices).</span><br><span class="line">    uint32_t styleCount;</span><br><span class="line"></span><br><span class="line">    // Flags.</span><br><span class="line">    enum &#123;</span><br><span class="line">        // If set, the string index is sorted by the string values (based</span><br><span class="line">        // on strcmp16()).</span><br><span class="line">        SORTED_FLAG = 1&lt;&lt;0,</span><br><span class="line"></span><br><span class="line">        // String pool is encoded in UTF-8</span><br><span class="line">        UTF8_FLAG = 1&lt;&lt;8</span><br><span class="line">    &#125;;</span><br><span class="line">    uint32_t flags;</span><br><span class="line"></span><br><span class="line">    // Index from header of the string data.</span><br><span class="line">    uint32_t stringsStart;</span><br><span class="line"></span><br><span class="line">    // Index from header of the style data.</span><br><span class="line">    uint32_t stylesStart;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResStringPoolHeader &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * 排序标记</span><br><span class="line">	 */</span><br><span class="line">	public final static int SORTED_FLAG = 1;</span><br><span class="line">	/**</span><br><span class="line">	 * UTF-8编码标识</span><br><span class="line">	 */</span><br><span class="line">	public final static int UTF8_FLAG = (1 &lt;&lt; 8);</span><br><span class="line">	/**</span><br><span class="line">	 * 标准的Chunk头部信息结构</span><br><span class="line">	 */</span><br><span class="line">	public ResChunkHeader header;</span><br><span class="line">	/**</span><br><span class="line">	 * 字符串的个数</span><br><span class="line">	 */</span><br><span class="line">	public int stringCount;</span><br><span class="line">	/**</span><br><span class="line">	 * 字符串样式的个数</span><br><span class="line">	 */</span><br><span class="line">	public int styleCount;</span><br><span class="line">	/**</span><br><span class="line">	 * 字符串的属性，可取值包括0x000(UTF-16)，0x001(字符串经过排序)，0x100(UTF-8)和他们的组合值</span><br><span class="line">	 */</span><br><span class="line">	public int flags;</span><br><span class="line">	/**</span><br><span class="line">	 * 字符串内容块相对于其头部的距离</span><br><span class="line">	 */</span><br><span class="line">	public int stringsStart;</span><br><span class="line">	/**</span><br><span class="line">	 * 字符串样式块相对于其头部的距离</span><br><span class="line">	 */</span><br><span class="line">	public int stylesStart;</span><br><span class="line">	</span><br><span class="line">	public ResStringPoolHeader() &#123;</span><br><span class="line">		header = new ResChunkHeader();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 获取当前String Pool Header所占字节数</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	public int getHeaderSize() &#123;</span><br><span class="line">		return header.getHeaderSize() + 4 + 4 + 4 + 4 + 4;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;header: &quot; + header.toString() + &quot;\n&quot; + &quot;stringCount: &quot; + stringCount + &quot;,styleCount: &quot; + styleCount </span><br><span class="line">				+ &quot;,flags: &quot; + flags + &quot;,stringStart: &quot; + stringsStart + &quot;,stylesStart: &quot; + stylesStart;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######5). Package数据块<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * Package数据块记录编译包的元数据</span><br><span class="line"> * </span><br><span class="line"> * struct ResTable_package</span><br><span class="line">&#123;</span><br><span class="line">    struct ResChunk_header header;</span><br><span class="line"></span><br><span class="line">    // If this is a base package, its ID.  Package IDs start</span><br><span class="line">    // at 1 (corresponding to the value of the package bits in a</span><br><span class="line">    // resource identifier).  0 means this is not a base package.</span><br><span class="line">    uint32_t id;</span><br><span class="line"></span><br><span class="line">    // Actual name of this package, \0-terminated.</span><br><span class="line">    uint16_t name[128];</span><br><span class="line"></span><br><span class="line">    // Offset to a ResStringPool_header defining the resource</span><br><span class="line">    // type symbol table.  If zero, this package is inheriting from</span><br><span class="line">    // another base package (overriding specific values in it).</span><br><span class="line">    uint32_t typeStrings;</span><br><span class="line"></span><br><span class="line">    // Last index into typeStrings that is for public use by others.</span><br><span class="line">    uint32_t lastPublicType;</span><br><span class="line"></span><br><span class="line">    // Offset to a ResStringPool_header defining the resource</span><br><span class="line">    // key symbol table.  If zero, this package is inheriting from</span><br><span class="line">    // another base package (overriding specific values in it).</span><br><span class="line">    uint32_t keyStrings;</span><br><span class="line"></span><br><span class="line">    // Last index into keyStrings that is for public use by others.</span><br><span class="line">    uint32_t lastPublicKey;</span><br><span class="line"></span><br><span class="line">    uint32_t typeIdOffset;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * Package数据块的整体结构</span><br><span class="line"> * String Pool</span><br><span class="line"> * Type String Pool</span><br><span class="line"> * Key String Pool</span><br><span class="line"> * Type Specification</span><br><span class="line"> * Type Info</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResTablePackage &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * Chunk的头部信息数据结构</span><br><span class="line">	 */</span><br><span class="line">	public ResChunkHeader header;</span><br><span class="line">	/**</span><br><span class="line">	 * 包的ID，等于package id,一般用户包的值Package Id为0X7F，系统资源包Pacage Id为0X01</span><br><span class="line">	 * 这个值会在构建public.xml中的id值时用到</span><br><span class="line">	 */</span><br><span class="line">	public int id;</span><br><span class="line">	/**</span><br><span class="line">	 * 包名</span><br><span class="line">	 */</span><br><span class="line">	public char[] name = new char[128];</span><br><span class="line">	/**</span><br><span class="line">	 * 类型字符串资源池相对头部的偏移</span><br><span class="line">	 */</span><br><span class="line">	public int typeStrings;</span><br><span class="line">	/**</span><br><span class="line">	 * 最后一个到处的public类型字符串在类型字符串资源池中的索引，目前这个值设置为类型字符串资源池的元素格尔书</span><br><span class="line">	 */</span><br><span class="line">	public int lastPublicType;</span><br><span class="line">	/**</span><br><span class="line">	 * 资源项名称字符串相对头部的偏移</span><br><span class="line">	 */</span><br><span class="line">	public int keyStrings;</span><br><span class="line">	/**</span><br><span class="line">	 * 最后一个导出的Public资源项名称字符串在资源项名称字符串资源池中的索引，目前这个值设置为资源项名称字符串资源池的元素个数</span><br><span class="line">	 */</span><br><span class="line">	public int lastPublicKey;</span><br><span class="line">	</span><br><span class="line">	public ResTablePackage() &#123;</span><br><span class="line">		header = new ResChunkHeader();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;header: &quot; + header.toString() + &quot;\n&quot; + &quot;,id= &quot; + id + &quot;,name: &quot; + name.toString() + </span><br><span class="line">				&quot;,typeStrings:&quot; + typeStrings + &quot;,lastPublicType: &quot; + lastPublicType + &quot;,keyStrings: &quot; + keyStrings </span><br><span class="line">				+ &quot;,lastPublicKey: &quot; + lastPublicKey;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######6). 类型规范数据块<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 类型规范数据块用来描述资源项的配置差异性。通过这个差异性，我们可以知道每个资源项的配置状况。</span><br><span class="line"> * 知道了一个资源项的配置状况之后，Android资源管理框架在检测到设备的配置信息发生变化之后，就</span><br><span class="line"> * 可以知道是否需要重新加载该资源项。类型规范数据块是按照类型来组织的，即每一种类型都对应有一个</span><br><span class="line"> * 类型规范数据块。</span><br><span class="line"> * </span><br><span class="line"> * struct ResTable_typeSpec</span><br><span class="line">&#123;</span><br><span class="line">    struct ResChunk_header header;</span><br><span class="line"></span><br><span class="line">    // The type identifier this chunk is holding.  Type IDs start</span><br><span class="line">    // at 1 (corresponding to the value of the type bits in a</span><br><span class="line">    // resource identifier).  0 is invalid.</span><br><span class="line">    uint8_t id;</span><br><span class="line">    </span><br><span class="line">    // Must be 0.</span><br><span class="line">    uint8_t res0;</span><br><span class="line">    // Must be 0.</span><br><span class="line">    uint16_t res1;</span><br><span class="line">    </span><br><span class="line">    // Number of uint32_t entry configuration masks that follow.</span><br><span class="line">    uint32_t entryCount;</span><br><span class="line"></span><br><span class="line">    enum &#123;</span><br><span class="line">        // Additional flag indicating an entry is public.</span><br><span class="line">        SPEC_PUBLIC = 0x40000000</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResTableTypeSpec &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * SPEC公共常量</span><br><span class="line">	 */</span><br><span class="line">	public final static int SPEC_PUBLIC = 0x40000000;</span><br><span class="line">	/**</span><br><span class="line">	 * Chunk的头部信息结构</span><br><span class="line">	 */</span><br><span class="line">	public ResChunkHeader header;</span><br><span class="line">	/**</span><br><span class="line">	 * 标识资源的Type ID,Type ID是指资源的类型ID。资源的类型有animator、anim、color、drawable、layout、menu、raw、string和xml等等若干种，每一种都会被赋予一个ID。</span><br><span class="line">	 */</span><br><span class="line">	public byte id;</span><br><span class="line">	/**</span><br><span class="line">	 * 保留，始终为0</span><br><span class="line">	 */</span><br><span class="line">	public byte res0;</span><br><span class="line">	/**</span><br><span class="line">	 * 保留，始终为0</span><br><span class="line">	 */</span><br><span class="line">	public short res1;</span><br><span class="line">	/**</span><br><span class="line">	 * 本类型资源项个数，即名称相同的资源项的个数</span><br><span class="line">	 */</span><br><span class="line">	public int entryCount;</span><br><span class="line">	</span><br><span class="line">	public ResTableTypeSpec() &#123;</span><br><span class="line">		header = new ResChunkHeader();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;header: &quot; + header.toString() + &quot;,id: &quot; + id + &quot;,res0: &quot; + res0 + </span><br><span class="line">				&quot;,res1: &quot; + res1 + &quot;,entryCount: &quot; + entryCount;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######7). 资源类型项数据块<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 类型资源项数据块用来描述资源项的具体信息，可以知道每一个资源项的名称、值和配置等信息。</span><br><span class="line"> * 类型资源项数据同样是按照类型和配置来组织的，即一个具有n个配置的类型一共对应有n个类型</span><br><span class="line"> * 资源项数据块。</span><br><span class="line"> * </span><br><span class="line"> * struct ResTable_type</span><br><span class="line">&#123;</span><br><span class="line">    struct ResChunk_header header;</span><br><span class="line"></span><br><span class="line">    enum &#123;</span><br><span class="line">        NO_ENTRY = 0xFFFFFFFF</span><br><span class="line">    &#125;;</span><br><span class="line">    </span><br><span class="line">    // The type identifier this chunk is holding.  Type IDs start</span><br><span class="line">    // at 1 (corresponding to the value of the type bits in a</span><br><span class="line">    // resource identifier).  0 is invalid.</span><br><span class="line">    uint8_t id;</span><br><span class="line">    </span><br><span class="line">    // Must be 0.</span><br><span class="line">    uint8_t res0;</span><br><span class="line">    // Must be 0.</span><br><span class="line">    uint16_t res1;</span><br><span class="line">    </span><br><span class="line">    // Number of uint32_t entry indices that follow.</span><br><span class="line">    uint32_t entryCount;</span><br><span class="line"></span><br><span class="line">    // Offset from header where ResTable_entry data starts.</span><br><span class="line">    uint32_t entriesStart;</span><br><span class="line">    </span><br><span class="line">    // Configuration this collection of entries is designed for.</span><br><span class="line">    ResTable_config config;</span><br><span class="line">&#125;;</span><br><span class="line"> * </span><br><span class="line"> * @author mazaiting</span><br><span class="line"> */</span><br><span class="line">public class ResTableType &#123;</span><br><span class="line">	/**</span><br><span class="line">	 * NO_ENTRY常量</span><br><span class="line">	 */</span><br><span class="line">	public final static int NO_ENTRY = 0xFFFFFFFF;</span><br><span class="line">	/**</span><br><span class="line">	 * Chunk的头部信息结构</span><br><span class="line">	 */</span><br><span class="line">	public ResChunkHeader header;</span><br><span class="line">	/**</span><br><span class="line">	 * 标识资源的Type ID</span><br><span class="line">	 */</span><br><span class="line">	public byte id;</span><br><span class="line">	/**</span><br><span class="line">	 * 保留，始终为0</span><br><span class="line">	 */</span><br><span class="line">	public byte res0;</span><br><span class="line">	/**</span><br><span class="line">	 * 保留，始终为0</span><br><span class="line">	 */</span><br><span class="line">	public short res1;</span><br><span class="line">	/**</span><br><span class="line">	 * 本类型资源项个数，指名称相同的资源项的个数</span><br><span class="line">	 */</span><br><span class="line">	public int entryCount;</span><br><span class="line">	/**</span><br><span class="line">	 * 资源项数组块相对头部的偏移值</span><br><span class="line">	 */</span><br><span class="line">	public int entriesStart;</span><br><span class="line">	/**</span><br><span class="line">	 * 指向一个ResTable_config，用来描述配置信息，地区，语言，分辨率等</span><br><span class="line">	 */</span><br><span class="line">	public ResTableConfig resConfig;</span><br><span class="line">	</span><br><span class="line">	public ResTableType() &#123;</span><br><span class="line">		header = new ResChunkHeader();</span><br><span class="line">		resConfig = new ResTableConfig();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 获取当前资源类型所占的字节数</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	public int getSize() &#123;</span><br><span class="line">		return header.getHeaderSize() + 1 + 1 + 2 + 4 + 4;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@Override</span><br><span class="line">	public String toString()&#123;</span><br><span class="line">		return &quot;header: &quot; + header.toString() + &quot;,id: &quot; + id + &quot;,res0: &quot; + res0 + &quot;,res1: &quot; + res1 + </span><br><span class="line">				&quot;,entryCount: &quot; + entryCount + &quot;,entriesStart: &quot; + entriesStart;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>######8). 代码解析<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br></pre></td><td class="code"><pre><span class="line">public class ParseResourceMain &#123;</span><br><span class="line">//	private final static String FILE_PATH = &quot;res/source.apk&quot;;</span><br><span class="line">	private final static String FILE_PATH = &quot;res/resources.arsc&quot;;</span><br><span class="line">	public static void main(String[] args) &#123;</span><br><span class="line">		</span><br><span class="line">//		byte[] arscArray = getArscFromApk(FILE_PATH);</span><br><span class="line">		byte[] arscArray = getArscFromFile(FILE_PATH); </span><br><span class="line">		</span><br><span class="line">		System.out.println(&quot;parse restable header ...&quot;);</span><br><span class="line">		ParseResourceUtil.parseResTableHeaderChunk(arscArray);</span><br><span class="line">		System.out.println(&quot;===================================&quot;);</span><br><span class="line">		System.out.println();</span><br><span class="line"></span><br><span class="line">		System.out.println(&quot;parse resstring pool chunk  ...&quot;);</span><br><span class="line">		ParseResourceUtil.parseResStringPoolChunk(arscArray);</span><br><span class="line">		System.out.println(&quot;===================================&quot;);</span><br><span class="line">		System.out.println();</span><br><span class="line">		</span><br><span class="line">		System.out.println(&quot;parse package chunk ...&quot;);</span><br><span class="line">		ParseResourceUtil.parsePackage(arscArray);</span><br><span class="line">		System.out.println(&quot;===================================&quot;);</span><br><span class="line">		System.out.println();</span><br><span class="line">		</span><br><span class="line">		System.out.println(&quot;parse typestring pool chunk ...&quot;);</span><br><span class="line">		ParseResourceUtil.parseTypeStringPoolChunk(arscArray);</span><br><span class="line">		System.out.println(&quot;===================================&quot;);</span><br><span class="line">		System.out.println();</span><br><span class="line">		</span><br><span class="line">		System.out.println(&quot;parse keystring pool chunk ...&quot;);</span><br><span class="line">		ParseResourceUtil.parseKeyStringPoolChunk(arscArray);</span><br><span class="line">		System.out.println(&quot;===================================&quot;);</span><br><span class="line">		System.out.println();</span><br><span class="line">		</span><br><span class="line">		/**</span><br><span class="line">		 * 解析正文内容</span><br><span class="line">		 * 正文内容就是ResValue值，也就是开始构建public.xml中的条目信息，和类型的分离不同的xml文件</span><br><span class="line">		 */</span><br><span class="line">		int resCount = 0;</span><br><span class="line">		while (!ParseResourceUtil.isEnd(arscArray.length)) &#123;</span><br><span class="line">			resCount++;</span><br><span class="line">			boolean isSpec = ParseResourceUtil.isTypeSpec(arscArray);</span><br><span class="line">			if (isSpec) &#123;</span><br><span class="line">				System.out.println(&quot;parse restype spec chunk ...&quot;);</span><br><span class="line">				ParseResourceUtil.parseResTypeSpec(arscArray);</span><br><span class="line">				System.out.println(&quot;===================================&quot;);</span><br><span class="line">				System.out.println();</span><br><span class="line">			&#125; else &#123;				</span><br><span class="line">				System.out.println(&quot;parse restype info chunk ...&quot;);</span><br><span class="line">				ParseResourceUtil.parseResTypeInfo(arscArray);</span><br><span class="line">				System.out.println(&quot;===================================&quot;);</span><br><span class="line">				System.out.println();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		System.out.println(&quot;res count: &quot; + resCount);</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	/**</span><br><span class="line">	 * 从文件中获取resouces.arsc</span><br><span class="line">	 * @param filePath 文件路径</span><br><span class="line">	 * @return</span><br><span class="line">	 */</span><br><span class="line">	private static byte[] getArscFromFile(String filePath) &#123;</span><br><span class="line">		byte[] srcByte = null;</span><br><span class="line">		InputStream is = null;</span><br><span class="line">		ByteArrayOutputStream baos = null;</span><br><span class="line">		try &#123;</span><br><span class="line">			is = new FileInputStream(filePath);</span><br><span class="line">			baos = new ByteArrayOutputStream();</span><br><span class="line">			byte[] buffer = new byte[1024];</span><br><span class="line">			int len = 0;</span><br><span class="line">			while ((len = is.read(buffer)) != -1) &#123;</span><br><span class="line">				baos.write(buffer, 0, len);				</span><br><span class="line">			&#125;</span><br><span class="line">			srcByte = baos.toByteArray();</span><br><span class="line">		&#125; catch (Exception e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125; finally &#123;</span><br><span class="line">			try &#123;</span><br><span class="line">				is.close();</span><br><span class="line">				baos.close();</span><br><span class="line">			&#125; catch (IOException e) &#123;</span><br><span class="line">				e.printStackTrace();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		return srcByte;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 从APK中获取resources.arsc文件</span><br><span class="line">	 * @param filePath 文件路径</span><br><span class="line">	 * @return resources.arsc文件二进制数据</span><br><span class="line">	 */</span><br><span class="line">	private static byte[] getArscFromApk(String filePath) &#123;</span><br><span class="line">		byte[] srcByte = null;</span><br><span class="line">		ZipFile zipFile = null;</span><br><span class="line">		InputStream is = null;</span><br><span class="line">		ByteArrayOutputStream baos = null;</span><br><span class="line">		try &#123;</span><br><span class="line">			zipFile = new ZipFile(filePath);</span><br><span class="line">			ZipEntry entry = zipFile.getEntry(&quot;resources.arsc&quot;);</span><br><span class="line">			is = zipFile.getInputStream(entry);</span><br><span class="line">			baos = new ByteArrayOutputStream();</span><br><span class="line">			byte[] buffer = new byte[1024];</span><br><span class="line">			int len = 0;</span><br><span class="line">			while ((len = is.read(buffer)) != -1) &#123;</span><br><span class="line">				baos.write(buffer, 0, len);				</span><br><span class="line">			&#125;</span><br><span class="line">			srcByte = baos.toByteArray();</span><br><span class="line">			zipFile.close();</span><br><span class="line">		&#125; catch (Exception e) &#123;</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		&#125; finally &#123;</span><br><span class="line">			try &#123;</span><br><span class="line">				is.close();</span><br><span class="line">				baos.close();</span><br><span class="line">			&#125; catch (IOException e) &#123;</span><br><span class="line">				e.printStackTrace();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		return srcByte;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####参考文章<br><a href="https://blog.csdn.net/jiangwei0910410003/article/details/50628894" target="_blank" rel="noopener">Android逆向之旅—解析编译之后的Resource.arsc文件格式</a></p>
<p>####<a href="https://gitee.com/mazaiting/app_protection/tree/master/ParseArsc" target="_blank" rel="noopener">代码下载</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Android-Plugin/Android-解析DEX文件/" rel="next" title="Android-解析DEX文件">
                <i class="fa fa-chevron-left"></i> Android-解析DEX文件
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Android-Plugin/Android-解析so文件/" rel="prev" title="Android-解析so文件">
                Android-解析so文件 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
